package com.socialmediaanalytics.client.interests;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.socialmediaanalytics.client.GWTEntryPoint;
import com.socialmediaanalytics.client.facebook.FacebookImage;
import com.socialmediaanalytics.client.model.User;

/** 
 * 
 * 
 * @Feature 
 */

public class ShowCommonInterests extends VerticalPanel {

	public static VerticalPanel panelInterests = new VerticalPanel();

	public ShowCommonInterests() {

		this.setSize("100%", "100%");

		this.setSpacing(15);

		this.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

		// this.add(new FacebookLogoutButton());

		this.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		HTML title = new HTML(
				"<b><font size=3>Friends Common Interests</font></b>");
		this.add(title);

		title.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				show();
			}
		});

		panelInterests.clear();

		this.add(panelInterests);

	}

	public static void show() {

		panelInterests.clear();

		int j = 0;

		HorizontalPanel hp = new HorizontalPanel();

		for (User friend : GWTEntryPoint.facebookFriends.values()) {

			if (!friend.getFacebookID().equals(
					GWTEntryPoint.facebookUser.getFacebookID())
					&& friend.getFacebookInterests() != null) {

				if (j % 3 == 0) {

					hp = new HorizontalPanel();

					hp.setWidth("400px");

					hp.setSpacing(13);

					panelInterests.add(hp);
				}

				String image = FacebookImage.getString(friend.getFacebookID(),
						friend.getFacebookName());

				HTML interests = new HTML("<br><br>" + image + "<br><b>"
						+ friend.getFacebookName() + "</b><br>"
						+ friend.getFacebookInterests());

				interests.setWidth("100px");

				hp.add(interests);

				j++;
			}
		}
	}
}
